<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2017/6/2
  Time: 14:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<style>
  .red{
    color:red;
  }
</style>

<div class="panel-body">
  <input type="hidden" id="chooseId" />
  <input type="hidden" id="isRed" />
  <div class="form-inline" id="tempWidth">
    <input type="hidden" id="parentId" value="${parentId}">
    <div class="row">
      <div class="col-sm-12 table-toolbar-left">
        <btn id="btn_add_ordertrack" class="btn btn-primary btn-sm"  ${isCreate}>
          <i class="ti-plus"> </i> 新建订单跟踪
        </btn>

        <btn id="btn_overcome_ordertrack" class="btn btn-warning btn-sm pull-right" style="margin-left: 5px">
          <i class="ti-star"> </i> 障碍克服
        </btn>
      </div>
    </div>
  </div>

  <div class="table-responsive" id="ordertrack_list_row">
    <table id="ordertrack_in_table"></table>
    <div id="ordertrack_in_page"></div>
  </div>
</div>

<div class="panel-footer">
  <a class="btn btn-default" id="apply-re-common2" href="javascript:void(0)">
    <i class="fa fa-lg fa-mail-reply"></i> 返回视图
  </a>
</div>

<script>

  $(function(){

    init_grid_ordertrack();
    jQuery("#ordertrack_in_table").jqGrid('setGridWidth',  $('div').data("table_global_width")-50);

  });

  function init_grid_ordertrack() {

    __init_jqgrid('ordertrack_in_table', 'ordertrack_in_page',
            '<%=path%>/com/orderTrack/list',
            ['订单跟踪时间', '订单完成比率', '是否有障碍问题', '障碍克服情况', '提交人','提交日期', '操作', 'id'],
            [
              {name: 'trackDate', index: 'trackDate', width: 100, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
              {name: 'rate', index: 'rate', width: 50, sortable: true, search: true, stype: 'text', searchoptions: {sopt: ['cn']}},
              {name: 'difficulty', index: 'difficulty', width: 50, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
              {name: 'overcome', index: 'overcome', width: 80, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
              {name: 'creater', index: 'creater', width: 100, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
              {name: 'createTime', index: 'createTime', width: 100, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
              {name: 'act', index: 'act', width: 200, fixed: true, sortable: false, search: false, formatter: actFormat},
              {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
            ],
            true,
            {
              postData: {parentId: $("#parentId").val()},
              gridComplete: function () {
                var ids = $("#ordertrack_in_table").getDataIDs();
                for (var i = 0; i < ids.length; i++) {
                  var rowData = $("#ordertrack_in_table").getRowData(ids[i]);
                  if(rowData.difficulty=="是"&&rowData.overcome=="未克服"){
                    $('#' + ids[i]).find("td").addClass("red");
                  }
                }
              },
              onSelectRow: function () {
                var rowId = $("#ordertrack_in_table").jqGrid('getGridParam','selrow');
                var rowDatas = $("#ordertrack_in_table").jqGrid('getRowData', rowId);
                $("#chooseId").val(rowId);
                if(rowDatas.difficulty=="是"&&rowDatas.overcome=="未克服"){
                  $("#isRed").val(1);
                }else{
                  $("#isRed").val(0);
                }
              }
            }
    );

  }

  function actFormat(cellvalue, options, rowObject){
    var id = rowObject.id;
    cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_ordertrack_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button>';
//    if(rowObject.difficulty=="是"&&rowObject.overcome=="未克服"){
//      cellvalue += '<button class="btn btn-white btn-sm" data-original-title="障碍克服" onclick="fn_ordertrack_overcome(\'' + id + '\');"><i class="fa fa-eye"> </i> 障碍克服</button>';
//    }

    return cellvalue;
  }

  function fn_ordertrack_read(id) {
    loadURL('<%=path%>/com/orderTrack/read?keyId='+id, $('#s2'));
  }

  <%--function fn_ordertrack_overcome(id) {--%>
    <%--__confirm_dialog("障碍克服","是否已克服障碍",function(){--%>
      <%--var url="<%=path%>/activiti/ordertrack/overcome";--%>
      <%--var params={keyId:id};--%>
      <%--__ajax_post(url,params,function(data){--%>
        <%--__toastr(data);--%>
        <%--$("#ordertrack_in_table").trigger("reloadGrid");--%>
      <%--});--%>
    <%--});--%>
  <%--}--%>

  //顶部的障碍克服
  $("#btn_overcome_ordertrack").click(function(){
    if($("#chooseId").val()==""||$("#chooseId").val()==null){
      __toastr_error("请选择一条订单");
    }else if($("#isRed").val()==0){
      __toastr_error("此记录不需要障碍克服");
    }else{
      __confirm_dialog("障碍克服","是否已克服障碍",function(){
        var url="<%=path%>/com/orderTrack/overcome";
        var params={keyId:$("#chooseId").val()};
        __ajax_post(url,params,function(data){
          __toastr(data);
          $('#ordertrack_in_table').jqGrid().setGridParam({datatype:'json'}).trigger('reloadGrid');
        });
      });
    }
  });

  $("#btn_add_ordertrack").click(function(){
    loadURL('<%=path%>/com/orderTrack/input?parentId='+$("#form_order_input #keyId").val(), $('#s2'));
  });

  //返回视图
  $("#apply-re-common2").click(returnToHashUrl);

</script>